package service.impl;

import dao.StoDao;
import dao.impl.StoDaoImpl;
import entity.Sto;
import service.StoService;

public class StoServiceImpl implements StoService {

	StoDao dao = new StoDaoImpl();
	/*
	 * stoid varchar(15) primary key, -- 进货流水号
  stoticket varchar(50) unique not null, -- 进货票号唯一
  paykind varchar(2) not null,   -- 结算种类：01现金，02银联，03支付宝， 04财付通
  stotime timestamp(6) not null, -- 进货时间
  stocount int(10) not null,     -- 进货数量
  stoprice double(10,2) not null, -- 进货单价
  stoperson varchar(20) not null, -- 进货人
  totalprice double(12,2) not null, -- 本次进货总价= 进货数量*进货单价
  wareid varchar(15),  -- 外键商品id
	 */
	@Override
	public boolean save(Sto sto) {
		// 验证
		if (sto.getStoid() != null && sto.getStoticket() != null && sto.getPaykind() != null && sto.getStotime() != null
				&& sto.getStocount() != 0 && sto.getStoprice() != 0.0 && sto.getStoperson() != null
				&& sto.getTotalprice() != 0.0 && sto.getWareid() != null) {
			
			String paykind = sto.getPaykind();
			switch (paykind) {
			case "01": 
			case "02": 
			case "03": 
			case "04": return dao.insert(sto);
			default: return false;
			}
			
		}else {
			return false;
		}
	}

	@Override
	public boolean modifyChkPersonAndChkVal(String stoticket, String chkperson, String chkval) {
		if (stoticket != null && chkperson != null && chkval != null)
			return dao.updatePersonAndChkVal(stoticket,chkperson,chkval);
		else 
			return false;
	}

}
